package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjWorkSuspendAnnex;
import com.zb.mapper.ZjWorkSuspendAnnexMapper;
import com.zb.service.ZjWorkSuspendAnnexService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 工单挂起附件表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-03-18
 */
@Service
public class ZjWorkSuspendAnnexServiceImpl extends ServiceImpl<ZjWorkSuspendAnnexMapper, ZjWorkSuspendAnnex> implements ZjWorkSuspendAnnexService {

    // 保存工单挂起图片附件
    @Override
    public void save(Long custAccId, Long suspendId, List<String> paths) {
        if (CollectionUtil.isEmpty(paths)) {
            return;
        }
        List<ZjWorkSuspendAnnex> annexList = new ArrayList<>();
        ZjWorkSuspendAnnex annex = null;
        for (String path : paths) {
            annex = new ZjWorkSuspendAnnex();
            annex.setId(IdWorker.getId());
            annex.setCustAccId(custAccId);
            annex.setWorkSuspendId(suspendId);
            annex.setPath(path);
            annexList.add(annex);
        }
        if (CollectionUtil.isNotEmpty(annexList)) this.saveBatch(annexList);
    }

    // 根据挂起工单ID获取附件图片
    @Override
    public List<ZjWorkSuspendAnnex> getByWorkSuspendId(Long workSuspendId) {
        QueryWrapper<ZjWorkSuspendAnnex> wrapper = new QueryWrapper<>();
        wrapper.select("path")
                .eq("work_suspend_id", workSuspendId);
        return this.list(wrapper);
    }
}
